package com.snake.springboot.custom.controller.bill;

import com.snake.springboot.custom.api.model.base.CallbackModel;
import com.snake.springboot.custom.api.request.bill.BilGoPayModel;
import com.snake.springboot.custom.api.request.bill.BillGoRetModel;
import com.snake.springboot.custom.api.request.bill.BillQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.response.bill.BillGoPayRsp;
import com.snake.springboot.custom.api.response.bill.BillRsp;
import com.snake.springboot.custom.api.service.bill.BillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>账单管理-账单信息
 * 类{@code Bill} </br>
 * 创建时间2025/4/6 10:10
 * @author yangxt
 * @see
 */
@Api(tags = "账单管理-账单信息")
@RestController
@RequestMapping("/bill")
public class BillController {
    @Autowired
    private BillService billService;
    @ApiOperation("去支付")
    @PostMapping("/go-pay")
    public ResponseResult<BillGoPayRsp> goPay(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) BilGoPayModel model) {
        BillGoPayRsp result = billService.goPay(model);
        return ResponseResultFactory.ucc("操作成功！", result);
    }


    @ApiOperation("去关闭")
    @PostMapping("/go-close")
    public ResponseResult<BillGoPayRsp> goClose(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) BilGoPayModel model) {
        billService.goClose(model);
        return ResponseResultFactory.ucc("操作成功！");
    }

    @ApiOperation("去退款")
    @PostMapping("/go-ret")
    public ResponseResult<BillGoPayRsp> goRet(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) BillGoRetModel model) {
        billService.goRet(model);
        return ResponseResultFactory.ucc("操作成功！");
    }


    @ApiOperation(value = "回调", hidden = true)
    @PostMapping("/callback")
    public ResponseResult<Object> callback(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody CallbackModel model) {
        billService.callback(model);
        return ResponseResultFactory.ucc("回调成功！");
    }

    @ApiOperation("删除单据信息")
    @GetMapping("/remove/{billId}")
    public ResponseResult<Object> remove(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @PathVariable String billId) {
        billService.remove(billId);
        return ResponseResultFactory.ucc("回调成功！");
    }

    @ApiOperation("查询账单详情")
    @GetMapping("/detail/{billId}")
    public ResponseResult<BillRsp> detail(
            @PathVariable String billId) {
        BillRsp rsp = billService.detail(billId);
        return ResponseResultFactory.ucc("查询账单详情成功！",rsp);
    }

    @ApiOperation("商户查询账单列表")
    @PostMapping("/cust/list")
    public ResponseResult<ReturnList<BillRsp>> custQueryBillList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<BillQuery> params) {
        params.getParams().setCustomId(params.getCustomId());
        ReturnList<BillRsp> result = billService.custQueryBillList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

    @ApiOperation("管理员查询账单列表")
    @PostMapping("/admin/list")
    public ResponseResult<ReturnList<BillRsp>> adminQueryBillList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody PageQuery<BillQuery> params) {
        ReturnList<BillRsp> result = billService.adminQueryBillList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }






}
